/*
 * RecipeSearchView.java
 */

package recipesearch;

import java.awt.CardLayout;
import org.jdesktop.application.Action;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import javax.swing.JDialog;
import javax.swing.JFrame;
import se.chalmers.ait.dat215.lab2.*;
import java.util.*;
import javax.swing.ButtonModel;
import javax.swing.JRadioButton;

/**
 * The application's main frame.
 */
public class RecipeSearchView extends FrameView {

    private List<Recipe> recipes;
    private final RecipeDatabase db;
    private CardLayout cardLayout;
    

    public RecipeSearchView(SingleFrameApplication app) {
        super(app);

        initComponents();

        this.getFrame().setIconImage(this.getResourceMap()
        .getImageIcon("frame.icon").getImage());
        
        db = RecipeDatabase.getSharedInstance();
        cardLayout = (CardLayout) cardPanel.getLayout();
        allRadio.setSelected(true);
        cardLayout.last(cardPanel);
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = RecipeSearchApp.getApplication().getMainFrame();
            aboutBox = new RecipeSearchAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        RecipeSearchApp.getApplication().show(aboutBox);
    }
    
    public void recipeSearch(RecipeQuery rq) {

        List<Recipe> temp = db.search(new SearchFilter(rq.getDifficulty(), rq.getTime(), rq.getCuisine(), rq.getPrice(), rq.getIngredient()));
        this.recipes = new ArrayList<Recipe>();
        for(Recipe r:temp) {
            if (r.getMatch() != 0){
                recipes.add(r);
            }
        }
        System.out.println(rq);


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        splitPane = new javax.swing.JSplitPane();
        leftPanel = new javax.swing.JPanel();
        cardPanel = new javax.swing.JPanel();
        resultPanel = new javax.swing.JPanel();
        resultLbl = new javax.swing.JLabel();
        scrollPane = new javax.swing.JScrollPane();
        resultList = new javax.swing.JList();
        returnBtn = new javax.swing.JButton();
        showMoreBtn = new javax.swing.JButton();
        searchPanel = new javax.swing.JPanel();
        searchLbl = new javax.swing.JLabel();
        cardBtn = new javax.swing.JButton();
        cuisineCombo = new javax.swing.JComboBox();
        ingredientCombo = new javax.swing.JComboBox();
        difficultyPanel = new javax.swing.JPanel();
        allRadio = new javax.swing.JRadioButton();
        easyRadio = new javax.swing.JRadioButton();
        mediumRadio = new javax.swing.JRadioButton();
        hardRadio = new javax.swing.JRadioButton();
        miscPanel = new javax.swing.JPanel();
        timeLbl = new javax.swing.JLabel();
        timeSpinner = new javax.swing.JSpinner();
        priceLbl = new javax.swing.JLabel();
        priceText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        recipeScrPane = new javax.swing.JScrollPane();
        recipeView = new recipesearch.RecipeView();
        difficultyBtnGroup = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N

        splitPane.setDividerLocation(300);
        splitPane.setName("splitPane"); // NOI18N

        leftPanel.setName("leftPanel"); // NOI18N

        cardPanel.setName("cardPanel"); // NOI18N
        cardPanel.setLayout(new java.awt.CardLayout());

        resultPanel.setName("resultPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(recipesearch.RecipeSearchApp.class).getContext().getResourceMap(RecipeSearchView.class);
        resultLbl.setText(resourceMap.getString("resultLbl.text")); // NOI18N
        resultLbl.setName("resultLbl"); // NOI18N

        scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane.setName("scrollPane"); // NOI18N

        resultList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        resultList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        resultList.setFixedCellHeight(50);
        resultList.setName("resultList"); // NOI18N
        resultList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                resultListValueChanged(evt);
            }
        });
        scrollPane.setViewportView(resultList);

        returnBtn.setIcon(resourceMap.getIcon("returnBtn.icon")); // NOI18N
        returnBtn.setText(resourceMap.getString("returnBtn.text")); // NOI18N
        returnBtn.setName("returnBtn"); // NOI18N
        returnBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                returnBtnActionPerformed(evt);
            }
        });

        showMoreBtn.setIcon(resourceMap.getIcon("showMoreBtn.icon")); // NOI18N
        showMoreBtn.setText(resourceMap.getString("showMoreBtn.text")); // NOI18N
        showMoreBtn.setName("showMoreBtn"); // NOI18N
        showMoreBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showMoreBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout resultPanelLayout = new org.jdesktop.layout.GroupLayout(resultPanel);
        resultPanel.setLayout(resultPanelLayout);
        resultPanelLayout.setHorizontalGroup(
            resultPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(resultPanelLayout.createSequentialGroup()
                .add(returnBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(showMoreBtn))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, resultPanelLayout.createSequentialGroup()
                .add(resultLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
                .addContainerGap())
            .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
        );
        resultPanelLayout.setVerticalGroup(
            resultPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(resultPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(resultLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(resultPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(returnBtn)
                    .add(showMoreBtn)))
        );

        cardPanel.add(resultPanel, "card2");

        searchPanel.setName("searchPanel"); // NOI18N
        searchPanel.setPreferredSize(new java.awt.Dimension(200, 434));

        searchLbl.setText(resourceMap.getString("searchLbl.text")); // NOI18N
        searchLbl.setName("searchLbl"); // NOI18N

        cardBtn.setIcon(resourceMap.getIcon("cardBtn.icon")); // NOI18N
        cardBtn.setText(resourceMap.getString("cardBtn.text")); // NOI18N
        cardBtn.setName("cardBtn"); // NOI18N
        cardBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cardBtnActionPerformed(evt);
            }
        });

        cuisineCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Alla", "Afrika", "Asien", "Frankrike", "Grekland", "Indien", "Sverige" }));
        cuisineCombo.setName("cuisineCombo"); // NOI18N

        ingredientCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Alla", "Fisk", "Kyckling", "Kött", "Vegetarisk" }));
        ingredientCombo.setName("ingredientCombo"); // NOI18N

        difficultyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("difficultyPanel.border.title"))); // NOI18N
        difficultyPanel.setName("difficultyPanel"); // NOI18N

        difficultyBtnGroup.add(allRadio);
        allRadio.setText(resourceMap.getString("allRadio.text")); // NOI18N
        allRadio.setActionCommand(null);
        allRadio.setName("allRadio"); // NOI18N

        difficultyBtnGroup.add(easyRadio);
        easyRadio.setText(resourceMap.getString("easyRadio.text")); // NOI18N
        easyRadio.setName("easyRadio"); // NOI18N
        easyRadio.setActionCommand(resourceMap.getString("easyRadio.text"));

        difficultyBtnGroup.add(mediumRadio);
        mediumRadio.setText(resourceMap.getString("mediumRadio.text")); // NOI18N
        mediumRadio.setName("mediumRadio"); // NOI18N
        mediumRadio.setActionCommand(resourceMap.getString("mediumRadio.text"));

        difficultyBtnGroup.add(hardRadio);
        hardRadio.setText(resourceMap.getString("hardRadio.text")); // NOI18N
        hardRadio.setName("hardRadio"); // NOI18N
        hardRadio.setActionCommand(resourceMap.getString("hardRadio.text"));

        org.jdesktop.layout.GroupLayout difficultyPanelLayout = new org.jdesktop.layout.GroupLayout(difficultyPanel);
        difficultyPanel.setLayout(difficultyPanelLayout);
        difficultyPanelLayout.setHorizontalGroup(
            difficultyPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(difficultyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(difficultyPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(allRadio)
                    .add(easyRadio)
                    .add(mediumRadio)
                    .add(hardRadio))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        difficultyPanelLayout.setVerticalGroup(
            difficultyPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(difficultyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(allRadio)
                .add(2, 2, 2)
                .add(easyRadio)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mediumRadio)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(hardRadio)
                .addContainerGap(78, Short.MAX_VALUE))
        );

        miscPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("miscPanel.border.title"))); // NOI18N
        miscPanel.setName("miscPanel"); // NOI18N

        timeLbl.setText(resourceMap.getString("timeLbl.text")); // NOI18N
        timeLbl.setName("timeLbl"); // NOI18N

        timeSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 150, 10));
        timeSpinner.setName("timeSpinner"); // NOI18N

        priceLbl.setText(resourceMap.getString("priceLbl.text")); // NOI18N
        priceLbl.setName("priceLbl"); // NOI18N

        priceText.setText(resourceMap.getString("priceText.text")); // NOI18N
        priceText.setName("priceText"); // NOI18N

        org.jdesktop.layout.GroupLayout miscPanelLayout = new org.jdesktop.layout.GroupLayout(miscPanel);
        miscPanel.setLayout(miscPanelLayout);
        miscPanelLayout.setHorizontalGroup(
            miscPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(miscPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(miscPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(timeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, Short.MAX_VALUE)
                    .add(timeLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
                    .add(priceLbl)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, priceText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE))
                .addContainerGap())
        );
        miscPanelLayout.setVerticalGroup(
            miscPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(miscPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(timeLbl)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(timeSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(priceLbl)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(priceText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(66, Short.MAX_VALUE))
        );

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        org.jdesktop.layout.GroupLayout searchPanelLayout = new org.jdesktop.layout.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(searchPanelLayout.createSequentialGroup()
                .add(cardBtn)
                .addContainerGap())
            .add(searchPanelLayout.createSequentialGroup()
                .add(jLabel2)
                .addContainerGap())
            .add(searchPanelLayout.createSequentialGroup()
                .add(jLabel1)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, searchPanelLayout.createSequentialGroup()
                .add(difficultyPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(miscPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(54, 54, 54))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, searchPanelLayout.createSequentialGroup()
                .add(searchLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE)
                .addContainerGap())
            .add(cuisineCombo, 0, 273, Short.MAX_VALUE)
            .add(ingredientCombo, 0, 273, Short.MAX_VALUE)
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(searchLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cuisineCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ingredientCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(searchPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(difficultyPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(miscPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE)
                .add(cardBtn))
        );

        cardPanel.add(searchPanel, "card3");

        org.jdesktop.layout.GroupLayout leftPanelLayout = new org.jdesktop.layout.GroupLayout(leftPanel);
        leftPanel.setLayout(leftPanelLayout);
        leftPanelLayout.setHorizontalGroup(
            leftPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(leftPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(cardPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
                .addContainerGap())
        );
        leftPanelLayout.setVerticalGroup(
            leftPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(leftPanelLayout.createSequentialGroup()
                .add(cardPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
                .addContainerGap())
        );

        splitPane.setLeftComponent(leftPanel);

        recipeScrPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        recipeScrPane.setName("recipeScrPane"); // NOI18N

        recipeView.setName("recipeView"); // NOI18N
        recipeScrPane.setViewportView(recipeView);

        splitPane.setRightComponent(recipeScrPane);

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(splitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 964, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(splitPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
        );

        setComponent(mainPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void resultListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_resultListValueChanged
       if(resultList.getSelectedIndex() >= 0)
           recipeView.setRecipe(recipes.get(resultList.getSelectedIndex())); 

    }//GEN-LAST:event_resultListValueChanged

    private void cardBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cardBtnActionPerformed
        RecipeQuery query = getQuery();
        recipeSearch(query);
        resultList.setListData(feedResultList(0));
        cardLayout.next(cardPanel);
    }//GEN-LAST:event_cardBtnActionPerformed

    private void showMoreBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showMoreBtnActionPerformed
        int selectedIndex = resultList.getSelectedIndex();
        resultList.setListData(feedResultList(resultList.getModel().getSize()));
        resultList.setSelectedIndex(selectedIndex);
    }//GEN-LAST:event_showMoreBtnActionPerformed

    private void returnBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_returnBtnActionPerformed
        cardLayout.next(cardPanel);
    }//GEN-LAST:event_returnBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton allRadio;
    private javax.swing.JButton cardBtn;
    private javax.swing.JPanel cardPanel;
    private javax.swing.JComboBox cuisineCombo;
    private javax.swing.ButtonGroup difficultyBtnGroup;
    private javax.swing.JPanel difficultyPanel;
    private javax.swing.JRadioButton easyRadio;
    private javax.swing.JRadioButton hardRadio;
    private javax.swing.JComboBox ingredientCombo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JRadioButton mediumRadio;
    private javax.swing.JPanel miscPanel;
    private javax.swing.JLabel priceLbl;
    private javax.swing.JTextField priceText;
    private javax.swing.JScrollPane recipeScrPane;
    private recipesearch.RecipeView recipeView;
    private javax.swing.JLabel resultLbl;
    private javax.swing.JList resultList;
    private javax.swing.JPanel resultPanel;
    private javax.swing.JButton returnBtn;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JLabel searchLbl;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JButton showMoreBtn;
    private javax.swing.JSplitPane splitPane;
    private javax.swing.JLabel timeLbl;
    private javax.swing.JSpinner timeSpinner;
    // End of variables declaration//GEN-END:variables


    private JDialog aboutBox;

    private String[] feedResultList(int size) {
        String[] recipeResults = new String[size+5];
        for(int i=0;i<size+5;i++){
            if(i<recipes.size()){
                Recipe r = recipes.get(i);
                recipeResults[i] = "<html><font size=\"4\"><b>" + r.getName()+ "</b></font><br>"
                        + r.getMatch()+"% match, " + r.getCuisine() + ", " +  r.getMainIngredient();
            }
        }
        showMoreBtn.setEnabled(size+5 < recipes.size());
        return recipeResults;
    }

    private RecipeQuery getQuery() {
        String difficulty = difficultyBtnGroup.getSelection().getActionCommand();
        int time = Integer.parseInt(timeSpinner.getValue().toString());
        String cuisine =cuisineCombo.getSelectedItem().toString();
        if (cuisineCombo.getSelectedIndex() == 0) {
            cuisine = null;
        }
        int price = Integer.parseInt(priceText.getText());
        String ingredient = ingredientCombo.getSelectedItem().toString();
        if (ingredientCombo.getSelectedIndex() == 0) {
            ingredient = null;
        }
        return new RecipeQuery(difficulty, time, ingredient, price, cuisine);
    }
}
